//
// Created by lingzhitech on 25-8-6.
//
// 主要是在第7章进行定义的
#ifndef SALES_DATA_H
#define SALES_DATA_H
#include <iostream>

// 对于普通的类的定义思路
class Sales_data {

    friend std::ostream &operator<<(std::ostream &, const Sales_data &);

    friend std::istream &operator>>(std::istream &, Sales_data &);

    friend bool operator==(const Sales_data &, const Sales_data &);


public: // access specifier added

    Sales_data() = default;

    Sales_data(const Sales_data &) = default;

    Sales_data &operator=(const Sales_data &) = default;

    ~Sales_data() = default;

    Sales_data(const std::string &s, unsigned n, double p): bookNo(s), units_sold(n), revenue(p * n) {
    };

    Sales_data(const std::string &s): bookNo(s) {
    };

    Sales_data(std::istream &);

    const std::string& isbn() const { return bookNo; }

    Sales_data &combine(const Sales_data &);

    Sales_data &operator+=(const Sales_data &);




private: // access specifier added
    double avg_price() const { return units_sold ? revenue / units_sold : 0; }
    std::string bookNo;
    unsigned units_sold = 0;
    double revenue = 0.0;
};

bool operator!=(const Sales_data &, const Sales_data &);

Sales_data operator+(const Sales_data &, const Sales_data &);
#endif //SALES_DATA_H
